package com.momathink.tpp;

import java.util.ArrayList;
import java.util.List;

import com.jfinal.plugin.activerecord.generator.MetaBuilder;
import com.jfinal.plugin.activerecord.generator.TableMeta;

public class _TppTest {

    public static void main(String[] args) {
    	
    	String string = "user_base";
    	String xx = formaString(string, "_");
    	System.out.println(xx);
    	/*JfinalInit.init();
    	MetaBuilder metaBuilder = new MetaBuilder(JfinalInit.druidPlugin.getDataSource());
    	List<TableMeta> metas = metaBuilder.build();
//        String className = "Test";
//        String tableName = "t_test";
        for (TableMeta tableMeta : metas) {
			String tableName = tableMeta.name;
			 String className = captureName(tableName);
			 
			 JfGenerator.me
		        .setSrcFolder("src/main/java")
		        .setViewFolder("src/main/webapp")
		        .setPackageBase("com")
		        .setBasePath("demo")
//		        .tableSql(getSqlList())
		        .javaRender(className, tableName);
//		        .htmlRender(className, tableName)
		}*/

       

        System.out.println("---------OK-刷新一下项目吧---------");
    }
    
    private static List<String> getSqlList() {
        ArrayList<String> sqlList = new ArrayList<String>();
        
        sqlList.add("DROP TABLE IF EXISTS `t_test`;");
        sqlList.add("CREATE TABLE `t_test` ( " +
                "  `id` int(11) NOT NULL AUTO_INCREMENT, " +
                "  `test` varchar(255) DEFAULT NULL, " +
                "  PRIMARY KEY (`id`) " +
                ") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
        
        return sqlList;
    }

    /**
     * 首字母大写
     * @param name
     * @return
     */
    public static String captureName(String name) {
        char[] cs=name.toCharArray();
        cs[0]-=32;
        return String.valueOf(cs);
        
    }
    
    /**
     * 若数据表名称内存在特殊字符分割，则移除特殊字符并将特殊字符后的字母大写
     * @param str
     * @param split
     * @return
     */
    public static String formaString(String str,String split) {
    	String[] xx = str.split(split);
    	String fString = "";
    	for (String string : xx) {
    		fString += captureName(string);
		}
    	return fString;
    }
    

}
